package com.l.okhttp;

import androidx.appcompat.app.AppCompatActivity;

import android.os.Bundle;
import android.util.Log;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.Callback;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;

public class MainActivity extends AppCompatActivity {

    static String tag = "hms";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        TestGet();
    }



    public static void TestGet() {
        String url = "https://api.apiopen.top/getSingleJoke?sid=28654780";
        OkHttpClient mClient = new OkHttpClient();
        final Request mRequest = new Request.Builder()
                .url(url)
                .get()
                .build();
        Call mCall = mClient.newCall(mRequest);
        mCall.enqueue(new Callback() {
            @Override
            public void onFailure(Call call, IOException e) {
            }
            @Override
            public void onResponse(Call call, Response response) throws IOException {
                Log.e(tag, "onResponse: "  + response.body().string());
            }
        });
    }
}
